package com.moon.controller;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.moon.utils.BaseController;
import com.moon.entity.Poetry;
import com.moon.es.PoetryEs;
import com.moon.es.PoetryReporsitory;
import com.moon.service.PoetryService;

@Controller
@RequestMapping("/moon/Poetry")
public class PoetryController extends BaseController {
	@Autowired
	private PoetryService poetryService;
	@Autowired
	private PoetryReporsitory poetryReporsitory;
	@RequestMapping("/initdata")
	public String selectAll() {
		List<Poetry> list=poetryService.getPoetryMapper().selectAll();
		for(Poetry poe : list) {
			PoetryEs p = new PoetryEs();
			BeanUtils.copyProperties(poe, p);
			poetryReporsitory.save(p);
			System.out.println(poe.getTitle());
		}
		return "tao/success";
	}
	@RequestMapping("/findByword")
	@ResponseBody
	public List<PoetryEs> findByWord(String word){
		return poetryReporsitory.findByContent(word);
	}
}